#include <stdio.h>
#include <string.h>

#include "Dequeue.h"

#define LINE_MAXLEN 128

const char *func_names[] = {
	"clear",	/* 0 */
	"pushfront",	/* 1 */
	"pushback",	/* 2 */
	"popfront",	/* 3 */
	"popback",	/* 4 */
	"front",	/* 5 */
	"back",		/* 6 */
	"isempty"	/* 7 */
};

const char *quit_cmd = "quit";


int
main(void)
{
	struct Dequeue d;
	char line[LINE_MAXLEN];
	int key = 0;

	d.head = 0;
	d.size = 0;

	while (scanf("%s", line) == 1) {
		if (!strcmp(line, func_names[0]))
			Clear(&d);
		else if (!strcmp(line, func_names[1]))
		{	/* Allman brace style :< */
			scanf("%d", &key);
			if (PushFront(&d, key) == -1)
				printf("\tFailed to push: DEQ overflow\n");
		}
		else if (!strcmp(line, func_names[2]))
		{
			scanf("%d", &key);
			if (PushBack(&d, key) == -1)
				printf("\tFailed to push: DEQ overflow\n");
		}
		else if (!strcmp(line, func_names[3]))
			printf(" %d\n", PopFront(&d));
		else if (!strcmp(line, func_names[4]))
			printf(" %d\n", PopBack(&d));
		else if (!strcmp(line, func_names[5]))
			printf(" %d\n", Front(&d));
		else if (!strcmp(line, func_names[6]))
			printf(" %d\n", Back(&d));
		else if (!strcmp(line, func_names[7]))
			printf(" %s\n", IsEmpty(&d) ? "Yes, DEQ is empty" : "Nay, it's not empty");
		else
			printf("\tWhat are talking about?\n");
	}
	fprintf(stderr, "  Leaving so soon?\n");
	return 0;
}
